/*
 * MOTOR.h
 *
 * Created: 18-06-2013 23:06:30
 *  Author: Karmu
 */ 


#ifndef MOTOR_H_
#define MOTOR_H_


/* defines for motor control */
#define M_L_PORT	PORTB
#define M_L_DDR		DDRB
#define M_L_IN1		PB4
#define M_L_IN2		PB5

#define M_R_PORT	PORTD
#define M_R_DDR		DDRD
#define M_R_IN1		PD3			//IN3
#define M_R_IN2		PD2			//IN4

#define M_PWM_PORT	PORTD
#define M_PWM_DDR	DDRD
#define M_L_PWM		PD5			//OC1A
#define M_R_PWM		PD4			//OC1B

#define MOTOR_L		1
#define MOTOR_R		2

#define M_FORWARD	0
#define M_REVERSE	1
#define M_STOP		2

#define GO_FORWARD		1
#define GO_REVERSE		2
#define GO_LEFT			3
#define GO_RIGHT		4
#define GO_HARD_LEFT	5
#define GO_HARD_RIGHT	6
#define GO_BRAKE		7

uint8_t pidSwitchLeft; //turn PID on/off for Left motor
uint8_t pidSwitchRight; //turn PID on/off for Right motor

/**
 @brief		Initialize motor pins
 @param		none
 @return	none
*/
extern void motor_init(void);

/**
 @brief		Initialize PWM Duty Cycle
 @param		top \b ICR1 value to get phase and frequency PWM \n
 @param		bottom \b OC1A and OC1B initial value to desired duty cycle\n
 @return	none
*/
extern void motor_pwm_timer1_init(uint16_t top, uint16_t bottom_right, uint16_t bottom_left);

/**
 @brief		Steer the bot in a direction
 @param		direction \b GO_LEFT, GO_HARD_LEFT, GO_FORWARD, GO_REVERSE, GO_HARD_RIGHT, GO_RIGHT, GO_BRAKE\n
 @return	direction \b GO_LEFT, GO_HARD_LEFT, GO_FORWARD, GO_REVERSE, GO_HARD_RIGHT, GO_RIGHT, GO_BRAKE\n
*/
extern uint8_t steer_robot(uint8_t direction);

extern void motor_speed_right(uint8_t speed);
extern void motor_speed_left(uint8_t speed);
#endif /* MOTOR_H_ */